<%--
  Created by IntelliJ IDEA.
  User: 3353611694
  Date: 2022/5/13
  Time: 8:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajaxForm.js"></script>
    <script>
        layui.config({
            base: '${pageContext.request.contextPath}/static/layui_exts/',//你存放authtree.js文件的位置
        }).extend({
            authtree: 'authtree',
        });
        layui.use(['jquery', 'authtree', 'form', 'layer'], function(){
            var $ = layui.jquery;
            var authtree = layui.authtree;
            var form = layui.form;
            var layer = layui.layer;
            // 表单提交样例
            form.on('submit(LAY-auth-tree-submit)', function(obj){
                var authids = authtree.getChecked('#LAY-auth-tree-index');
                obj.field.authids = authids;
                console.log(obj.field);
                console.log(name);
                $.ajax({
                    type:'post',
                    url: '${pageContext.request.contextPath}/juris/qunxianxui',
                    dataType: 'json',
                    data: obj.field,
                    success: function(res){
                        var index = parent.layer.getFrameIndex(window.name);//获取Frame索引
                        parent.layer.close(index);//关闭当前frame
                        parent.layui.table.reload("demo");//可以对父窗口进行刷新
                    }
                });
                return false;
            });
            $.ajax({
                url: '${pageContext.request.contextPath}/juris/zhuangtuli',
                dataType: 'json',
                success: function(res){
                    var trees = authtree.listConvert(res.data.list, {
                        primaryKey: 'moduleId' //标志，名字根据json可改
                        ,startPid: 0  //起始id（根节点），根据json填写
                        ,parentKey: 'root' //父节点id，名字根据json可改
                        ,nameKey: 'moduleName' //名称，名字根据json可改
                        ,valueKey: 'moduleId' //value值，名字根据json可改
                        ,checkedKey: res.data.checkedId//控制是否选中，checkedId是json中的数据
                        ,disabledKey: res.data.disabledId//控制是否可以获得，disabledId是json中的数据
                    });
                    // 如果页面中多个树共存，需要注意 layfilter 需要不一样
                    authtree.render('#LAY-auth-tree-index', trees, {
                        inputname: 'authids[]',
                        layfilter: 'lay-check-convert-auth',
                        openall: false,
                        autowidth: true,
                    });
                },
            });
        });
    </script>
</head>

<body>
<!-- 此扩展能递归渲染一个权限树，点击深层次节点，父级节点中没有被选中的节点会被自动选中，单独点击父节点，子节点会全部 选中/去选中 -->
<%--注意：id="LAY-auth-tree-index" 是整颗树的容器，需要包含在 form.layui-form > div.layui-form-item > div.layui-input-block 中，否则依照 layui 的规则无法渲染多选框--%>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">角色名称</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text"  name="name" value="${sessionScope.characterName}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择权限</label>
        <div class="layui-input-block">
            <div id="LAY-auth-tree-index"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="submit" lay-submit lay-filter="LAY-auth-tree-submit">提交</button>
            <button class="layui-btn layui-btn-primary" type="reset">重置</button>
        </div>
    </div>
</form>
</body>
</html>
